#include "qplotx.h"

class CFuncXAdapter : public Function
{
	CFuncX *m_f;
public:

	CFuncXAdapter(CFuncX * f, SurfacePlot& pw):Function(pw), m_f(f)
	{
	}

	double operator()(double x, double y)
	{
		vector<double> t(2);
		t[0] = x;
		t[1] = y;
		return m_f->operator ()(t);
	}
};

QPlotX::QPlotX(QWidget *parent):SurfacePlot(parent)
{
}

void QPlotX::plot(CFuncX *f, const Piped &p, const vector<double> &min, const list<vector<double> > &listOfExperiments)
{
	if (p.size() != 2)
	{
		//needed clear picture
		return;
	}

	setTitle("f(x,y)");

	CFuncXAdapter myf(f, *this);

	myf.setMesh(100,100);
	myf.setDomain(p[0].a,p[0].b,p[1].a,p[1].b);
	//myf.setMinZ(-10);

	myf.create();

	setRotation(30,0,15);
	setScale(1,1,1);
	setShift(0.15,0,0);
	setZoom(2.0);

	for (unsigned i=0; i!=coordinates()->axes.size(); ++i)
	{
		coordinates()->axes[i].setMajors(7);
		coordinates()->axes[i].setMinors(4);
	}


	coordinates()->axes[X1].setLabelString("x-axis");
	coordinates()->axes[Y1].setLabelString("y-axis");
	//coordinates()->axes[Z1].setLabelString(QChar(0x38f)); // Omega - see http://www.unicode.org/charts/


	setCoordinateStyle(BOX);


	for(list<vector<double> >::const_iterator it = listOfExperiments.begin(); it != listOfExperiments.end(); ++it)
	{
		Label *l = new Label("Arial", 10, 10, false);
		l->setString("*");
		l->setPosition(Triple((*it)[1], (*it)[2], (*it)[0]),BottomCenter);
		//l->setColor( 1.0,1.0,0.0,1.0);
		this->coordinates()->attach(l);
	}
	//add label min
	Label *l = new Label("Arial", 20, 20, false);
	l->setString("min");
	l->setPosition(Triple(min[1], min[2], min[0]),BottomCenter);
	this->coordinates()->attach(l);

	//this->showColorLegend(true);
	updateData();
	updateGL();
}
